package main

import (
	"fmt"
	"time"
)

func main() {
	//一个基本的switch用法
	i := 2
	fmt.Println("write", i, " as ")
	switch i {
	case 1:
		fmt.Println("one")
	case 2:
		fmt.Println("two")
	case 3:
		fmt.Println("three")
	}

	//在同一个case语句中可以使用逗号来分隔多个表达式
	switch time.Now().Weekday() {
	case time.Saturday, time.Sunday:
		fmt.Println("today is weekend")
	default:
		fmt.Println("today is a weekday")
	}

	//不带表达式的switch是实现if/else逻辑的另一种方式
	t := time.Now()
	fmt.Println("当前时间是 ", t)
	switch {
	case t.Hour() < 12:
		fmt.Println("now is before noon")
	default:
		fmt.Println("now is after noon")
	}
	whatAmi := func(i interface{}) {
		switch t := i.(type) {
		case bool:
			fmt.Println("i am bool")
		case int:
			fmt.Println("i am int")
		default:
			fmt.Printf("do not know type %T\n ", t)
		}
	}
	whatAmi(true)
	whatAmi(1)
	whatAmi("hey")

}
